﻿<Window Name="AppWindow" x:Class="AlanAamy.Net.TemperatureConverter.Views.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:behaviours="clr-namespace:AlanAamy.Net.TemperatureConverter.Infrastructure.Behaviours"
      mc:Ignorable="d" 
        DataContext="{Binding Path=MainPage, Source={StaticResource Locator}}"
      Title="Temperature Converter (C) Arup Banerjee, 2015" MinHeight="325" MinWidth="575" MaxWidth="575" 
        Height="Auto" SizeToContent="WidthAndHeight" Icon="..\Infrastructure\Resources\temperature-64x64.png">
    <Border DockPanel.Dock="Top" MinHeight="300"  MaxWidth="550"  BorderThickness="3" BorderBrush="WhiteSmoke" CornerRadius="10" Margin="5,5,5,5"
        HorizontalAlignment="Center" VerticalAlignment="Center">
        <Border.Resources>
        </Border.Resources>
        <Grid >
            <Grid.Resources>
                <Style x:Key="titleText" TargetType="{x:Type Label}">
                    <Setter Property="FontWeight" Value="Bold"/>
                    <Setter Property="FontSize" Value="24"/>
                    <!--<Setter Property="Margin" Value="10,5,10,10"/>-->
                    <Setter Property="Background" Value="WhiteSmoke"/>
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                    <Setter Property="HorizontalAlignment" Value="Center"/>
                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                    <Setter Property="VerticalAlignment" Value="Stretch"/>
                </Style>
                <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}">
                    <Border Background="{TemplateBinding Background}" 
                x:Name="Bd" BorderBrush="WhiteSmoke"
                BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10" >
                        <ScrollViewer x:Name="PART_ContentHost"/>
                    </Border>
                    <!--<ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                        <Trigger Property="Width" Value="Auto">
                            <Setter Property="MinWidth" Value="100"/>
                        </Trigger>
                        <Trigger Property="Height" Value="Auto">
                            <Setter Property="MinHeight" Value="20"/>
                        </Trigger>
                    </ControlTemplate.Triggers>-->
                </ControlTemplate>
                
            </Grid.Resources>
            <!-- Main content container -->
            <Grid.RowDefinitions>
                <RowDefinition Height="100" />
                <RowDefinition Height="70" />
                <RowDefinition Height="70" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="250"/>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition Width="250"/>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.ColumnSpan="3" Style="{StaticResource titleText}"  Content="Temperature Conversion" Margin="10,5,10,10"/>
            <TextBox Grid.Row="1" Grid.ColumnSpan="1" 
                     Text="{Binding LeftSequence, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource StringConverter}}" 
                     Name="LeftTextBox" FontSize="24"   Template="{StaticResource TextBoxBaseControlTemplate}"  
                     BorderThickness="2" TextAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                     behaviours:KeyboardFocus.Command="{Binding Path=ObserveInputSequence}" 
                     behaviours:KeyboardFocus.CommandParameter="{Binding SelectedItem, ElementName=CmbLeftConversionUnit }"/>
            <ComboBox Grid.Row="2" Grid.ColumnSpan="1" Name="CmbLeftConversionUnit"  Width="{Binding ElementName=LeftTextBox, Path=ActualWidth}" ItemsSource="{Binding Source={StaticResource TemperatureUnits}}" 
                      SelectedValue="{Binding CurrentLeftTemperatureUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      Style="{StaticResource ComboBoxFlatStyle}" Background="WhiteSmoke">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}"
                                 FontSize="24" TextAlignment="Center"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <TextBlock Grid.Row="1" Grid.Column="1" Text="=" FontSize="44"  HorizontalAlignment="Center" />
            
            <TextBox Grid.Row="1" Grid.Column="2" 
                     Text="{Binding RightSequence, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource StringConverter}}" 
                     Name="RightTextBox" FontSize="24"  Template="{StaticResource TextBoxBaseControlTemplate}" 
                     BorderThickness="2" TextAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                     behaviours:KeyboardFocus.Command="{Binding Path=ObserveInputSequence}" 
                     behaviours:KeyboardFocus.CommandParameter="{Binding SelectedItem, ElementName=CmbRightConversionUnit }"/>
            <ComboBox Grid.Row="2" Grid.Column="2" Name="CmbRightConversionUnit"  Width="{Binding ElementName=RightTextBox, Path=ActualWidth}"
                      HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource TemperatureUnits}}" 
                      SelectedValue="{Binding CurrentRightTemperatureUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      Style="{StaticResource ComboBoxFlatStyle}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}"
                                 FontSize="24" TextAlignment="Center"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Expander Template="{StaticResource StretchyExpanderTemp}" OverridesDefaultStyle="True" 
                      Grid.Row="3" Grid.ColumnSpan="3"   MaxHeight="200" >
                <Expander.Style>
                    <Style TargetType="Expander">
                        <Setter Property="IsExpanded" Value="False" />
                        <Setter Property="Header" Value="More Information" />

                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsExpanded,RelativeSource={RelativeSource Self}}" Value="True">
                                <Setter Property="Header" Value="Less Information" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Expander.Style>
                <ScrollViewer VerticalScrollBarVisibility="Auto">
                <StackPanel Margin="10,4,0,0">
                        <ListBox ItemsSource="{Binding LogMessages}"/>
                </StackPanel>
                </ScrollViewer>
            </Expander>
        </Grid>
    </Border>
</Window>
